package com.corona.game;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector3;
import com.corona.Game;
import com.corona.game.action.DrawAction;
import com.corona.game.util.GameProfiler;
import com.corona.game.util.SmolSprite;
import com.corona.game.util.SmolSpriteProxy;
import com.corona.game.util.TextureCache;
import com.corona.game.util.texture.DynamicTextures;
import java.util.Iterator;

/* compiled from: PkmnMap.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawMap.class */
public class DrawMap extends DrawAction {
    Vector3 startPos;
    Vector3 endPos;
    Tile tile;
    Sprite redrawThis;
    public Action.Layer layer = Action.Layer.map_140;
    Sprite spritePart = new Sprite();
    int zsTimer = 0;
    float done1 = 0.0f;
    float done2 = 0.0f;
    float done3 = 0.0f;
    Color prevColor = new Color();
    SmolSprite belowBridgeSprite = TextureCache.getTileSprite("bridge1_lower");

    public DrawMap(GameProfiler profiler) {
        super(profiler);
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.action.DrawAction
    protected void draw(Game game) {
        if (!game.player.dontDrawMapDuringBattle) {
            int i = 0;
            while (!game.map.minimapQueue.isEmpty() && i < 2) {
                game.map.minimapQueue.remove(0).updateMiniMap(game);
                i++;
            }
            this.done1 = 0.0f;
            this.done2 = 0.0f;
            this.done3 = 0.0f;
            game.map.setView(game, game.cam);
            Iterator<Tile> it = game.map.onscreenSpriteProxies.iterator();
            while (it.hasNext()) {
                Tile tile = it.next();
                game.mapBatch.draw((SmolSpriteProxy) tile.sprite, tile.sprite.getX(), tile.sprite.getY());
            }
            Iterator<Tile> it2 = game.map.onscreenSprites.iterator();
            while (it2.hasNext()) {
                Tile tile2 = it2.next();
                game.mapBatch.draw(tile2.sprite, tile2.sprite.getX(), tile2.sprite.getY());
            }
            Iterator<Tile> it3 = game.map.onscreenShoreOcean.iterator();
            while (it3.hasNext()) {
                Tile tile3 = it3.next();
                if (tile3.shoreOcean != null) {
                    game.mapBatch.draw(DynamicTextures.get(tile3.shoreOcean, MoveWater.shoreIndex), tile3.sprite.getX(), tile3.sprite.getY());
                }
            }
            this.prevColor.set(game.mapBatch.getColor());
            game.mapBatch.setColor(this.prevColor.r, this.prevColor.g, this.prevColor.b, 0.5f);
            Iterator<Tile> it4 = game.map.onscreenShoreTidal.iterator();
            while (it4.hasNext()) {
                Tile tile4 = it4.next();
                if (tile4.shoreTidal != null) {
                    game.mapBatch.draw(DynamicTextures.get(tile4.shoreTidal, MoveWater.shoreIndex), tile4.sprite.getX(), tile4.sprite.getY());
                }
            }
            game.mapBatch.setColor(this.prevColor);
            Iterator<Tile> it5 = game.map.onscreenBelowBridgeTiles.iterator();
            while (it5.hasNext()) {
                Tile tile5 = it5.next();
                game.mapBatch.draw(this.belowBridgeSprite, tile5.position.x, tile5.position.y);
            }
            Iterator<Tile> it6 = game.map.onscreenOverSprites.iterator();
            while (it6.hasNext()) {
                Tile tile6 = it6.next();
                if (tile6.overSprite != null) {
                    game.mapBatch.draw(tile6.overSprite, tile6.overSprite.getX(), tile6.overSprite.getY() - ((float) tile6.yOffset));
                }
            }
            Iterator<Tile> it7 = game.map.onscreenSavannaTrees.iterator();
            while (it7.hasNext()) {
                Tile tile7 = it7.next();
                game.mapBatch.draw(tile7.overSprite, tile7.overSprite.getX(), tile7.overSprite.getY());
            }
            if (game.playerCanMove) {
                Iterator<Pokemon> it8 = game.map.onscreenEggs.iterator();
                while (it8.hasNext()) {
                    Pokemon pokemon = it8.next();
                    Pokemon.Standing standingAction = (Pokemon.Standing) pokemon.standingAction;
                    float volume = 1.0f - (pokemon.position.dst2(game.player.position.x, game.player.position.y) / 52480.0f);
                    if (standingAction.danceCounter == 0 && volume > this.done1) {
                        this.done1 = volume;
                    } else if (standingAction.danceCounter == 16 && volume > this.done2) {
                        this.done2 = volume;
                    } else if (standingAction.danceCounter == 90 && volume > this.done3) {
                        this.done3 = volume;
                    }
                }
                if (this.done1 > 0.0f) {
                    game.insertAction(new PlayMusic("ledge2", this.done1, (Action) null));
                }
                if (this.done2 > 0.0f) {
                    game.insertAction(new PlayMusic("ledge2", this.done2, (Action) null));
                }
                if (this.done3 > 0.0f) {
                    game.insertAction(new PlayMusic("headbutt1", this.done3, (Action) null));
                }
            }
            for (Player player : game.players.values()) {
                if (player.network.tiles == game.map.tiles) {
                    if (player.isSleeping) {
                        player.zSprite.draw(game.mapBatch);
                        game.mapBatch.draw(player.sleepingSprite, player.position.x, player.position.y);
                    } else {
                        player.currSprite.setPosition(player.position.x, player.position.y + 4.0f);
                        player.currSprite.draw(game.mapBatch);
                    }
                }
            }
        }
    }
}
